package youcaihuaoa.weetop.com.ui.adapter

import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.GroupAddBean
import youcaihuaoa.weetop.com.R


class MessageGroupAdapter(var type: Int = 1) :
    BaseQuickAdapter<GroupAddBean, BaseViewHolder>(R.layout.app_item_message_group) {
    override fun convert(holder: BaseViewHolder, item: GroupAddBean) {
        holder.setText(R.id.item_tv_head, item.title?.first().toString())
            .setText(R.id.item_tv_name, item.title ?: "")
            .setText(R.id.item_tv_people_num, "${item.count_num ?: 0}人")
            .setText(
                R.id.item_tv_add, if (type == 1) {
                    "解散"
                } else {
                    "退出"
                }
            )
            .setText(R.id.item_tv_message_num, "${item.messageNumber}")
            .setGone(R.id.item_tv_message_num, item.messageNumber == 0)
            .setGone(R.id.item_v_line, holder.adapterPosition == data.size - 1)

        holder.getView<AppCompatTextView>(R.id.item_tv_add)
            .setOnClickListener {
                if(getOnItemClickListener() != null){
                    getOnItemClickListener()?.onItemClick(this, it, holder.adapterPosition)
                }
            }
    }
}